﻿

namespace Xfs
{
	[XfsObjectSystem]
	public class XfsLocationProxyComponentSystem : XfsAwakeSystem<XfsLocationProxyComponent>
	{
		public override void Awake(XfsLocationProxyComponent self)
		{
			self.Awake();
		}
	}

	public static class LocationProxyComponentEx
	{
		public static void Awake(this XfsLocationProxyComponent self)
		{

			//XfsStartConfig startConfig = startConfigComponent.LocationConfig;
			//self.LocationAddress = startConfig.GetComponent<XfsInnerConfig>().IpEndPoint;
		}

		public static async XfsTask Add(this XfsLocationProxyComponent self, long key, long instanceId)
		{
			XfsSession session = XfsGame.XfsSence.GetComponent<XfsNetInnerComponent>().Get(self.LocationAddress);
			
			//await session.Call(new XfsObjectAddRequest() { Key = key, InstanceId = instanceId });
			
			await session.Call(new C2S_TestRequest() );
		}

		public static async XfsTask Lock(this XfsLocationProxyComponent self, long key, long instanceId, int time = 1000)
		{
			XfsSession session = XfsGame.XfsSence.GetComponent<XfsNetInnerComponent>().Get(self.LocationAddress);
			
			//await session.Call(new XfsObjectLockRequest() { Key = key, InstanceId = instanceId, Time = time });
			
			await session.Call(new C2S_TestRequest());
		}

		public static async XfsTask UnLock(this XfsLocationProxyComponent self, long key, long oldInstanceId, long instanceId)
		{
			XfsSession session = XfsGame.XfsSence.GetComponent<XfsNetInnerComponent>().Get(self.LocationAddress);
			
			//await session.Call(new XfsObjectUnLockRequest() { Key = key, OldInstanceId = oldInstanceId, InstanceId = instanceId});
			
			await session.Call(new C2S_TestRequest());
		}

		public static async XfsTask Remove(this XfsLocationProxyComponent self, long key)
		{
			XfsSession session = XfsGame.XfsSence.GetComponent<XfsNetInnerComponent>().Get(self.LocationAddress);
			
			//await session.Call(new XfsObjectRemoveRequest() { Key = key });
			
			await session.Call(new C2S_TestRequest());
		}

        //public static async XfsTask<long> Get(this XfsLocationProxyComponent self, long key)
        //{
        //    XfsSession session = XfsGame.XfsSence.GetComponent<XfsNetInnerComponent>().Get(self.LocationAddress);

        //    //XfsObjectGetResponse response = (XfsObjectGetResponse)await session.Call(new XfsObjectGetRequest() { Key = key });
        //    //return testResponse.InstanceId;

        //    S2C_TestResponse testResponse = await session.Call(new C2S_TestRequest()) as S2C_TestResponse;
        //    return new XfsTaskCompletionSource<long>().Task;
        //}


	}
}